<%@ page contentType="text/html;charset=UTF-8" %>
<%@include file="/mb/jsp/common.jsp" %>

<%@ page language="java" import="java.util.*" %>
<%@ page language="java" import="java.lang.*" %>
<%@ page language="java" import="java.io.*" %>
<%@ page language="java" import="com.wsu.search.tools.Tools" %>
<%@ page language="java" import="com.limao.Tool.CacheClass" %>
<%@ page language="java" import="com.limao.CacheManager.sys_AdvCacheManager" %>
<%@ page language="java" import="com.limao.DBDataClass.AdvDataClass" %>
<%@ page language="java" import="com.limao.CacheManager.CrowdSysCateCache" %>
<%@ page language="java" import="com.limao.DBDataClass.SysProjectCateDataClass" %>
<%@ page language="java" import="com.limao.CacheManager.CrowdHomeCommendCache" %>
<%@ page language="java" import="com.limao.DBDataClass.CrowdHomeCommendClass" %>
<%@ page language="java" import="com.limao.DBDataClass.CrowdSysProjectClass" %>

<%
    /*
     网站首页生成程序
     */

    //取得url带过来的参数
    // String v = Tools.RmNull(request.getParameter("v"));
    String v = "show";

    /*************读写模板文件操作*****************/

    //读模板,先判断此信息最终极分类有没有,没有读t_type c_belong根栏目分类模板,还没有读news_info.html资讯类默认模板
//    String filename = request.getRealPath("model/mod_index_mb.html");
//    System.out.println(filename);
//    File fileobj = new File(filename);
//    if (!fileobj.exists()) {
//        //如果模板文件找不到
//        out.println("<font color=red>出错了,模板mod_index_mb.html文件找不到或丢失!</font>");
//        return;
//    }
//    StringBuffer strb = Tools.readFile(filename);

    /************* 广告图 *****************/

    //先调 用接口取得广告图数据
    List<AdvDataClass> advlist = sys_AdvCacheManager.getInstance().Load_SysHomeAdv();
    //数据与样式进行结合，组装
    String tmpStrAdvround = "", tmpStrAdvImage = "";
    int index = 1;
    if (advlist != null && advlist.size() > 0) {
        for (AdvDataClass obj : advlist) {
            tmpStrAdvround = tmpStrAdvround + "<a href=\"" + "\">" + index + "</a>";  //广告圆点
            if (CacheClass.getIntValue(obj.type) == 0) //跳转网页
                tmpStrAdvImage = tmpStrAdvImage + "<li><a href=\"" + obj.weburl + "\" ><span style=\"background:url(" + getImageBasePath(obj.imgurl) + ") center top no-repeat;background-size: cover;\"></span></li>";
            else  //跳转众筹项目
                tmpStrAdvImage = tmpStrAdvImage + "<li><a href=\"" + obj.weburl + "\" ><span style=\"background:url(" + getImageBasePath(obj.imgurl) + ") center top no-repeat;background-size: cover;\"></span></a></li>";
            index++;
        }
    }
    //数据填充
//    strb = Tools.replaceAll(strb, "[广告图圆点]", tmpStr1);
//    strb = Tools.replaceAll(strb, "[广告图图片]", tmpStr2);


    /***************** 菜单项  *****************/

    //先调 用接口取得众筹分类列表数据 --《接口文档》
    List<SysProjectCateDataClass> catlist = CrowdSysCateCache.getInstance().loadProjectCateJson();
    //数据与样式进行结合，组装
    String tmpStrFastMenu = "";
    index = 0;
    if (catlist != null && catlist.size() > 0) {
        for (SysProjectCateDataClass obj : catlist) {
            if (index == 7) { //当有8个，且为第8个时,在最后加 其它并中断for
                tmpStrFastMenu = tmpStrFastMenu + "<a href=\"mb/jsp/classification.jsp?cateid=" + obj.cateid + "\"><img src=\"mb/images/qita.png\" class=\"navImg\"><i>其他</i></a></div>";
                break;
            }
            int mod = index % 4; // 一行4个  开头
            if (mod == 0) {
                tmpStrFastMenu = tmpStrFastMenu + "<div class=\"w100 clearfix of\" style=\"margin-top:2px;\">";
            }
            tmpStrFastMenu = tmpStrFastMenu + "<a href=\"mb/jsp/classification.jsp?cateid=" + obj.cateid + "\"><img src=\"" + getImageBasePath(obj.cateimage) + "\" class=\"navImg\"><i>" + obj.catename + "</i></a>";

            index++;
            if (index % 4 == 0)  // 一行4个  结尾
            {
                tmpStrFastMenu = tmpStrFastMenu + "</div>";
            }
        }
        //当不足8个时,在最后加 其它
        if (index < 7) {
            tmpStrFastMenu = tmpStrFastMenu + "<a href=\"mb/jsp/classification.jsp?cateid=" + "8" + "\"><img src=\"mb/images/qita.png\" class=\"navImg\"><i>其他</i></a></div>";
        }
    }
    // System.out.println(tmpStr);
    //数据填充
    // strb = Tools.replaceAll(strb, "[首页快捷菜单]", tmpStr);


    /***************** 众筹首页推荐列表     *****************/

    //先调 用接口取得众筹主页推荐列表数据 --《接口文档》
    List<CrowdHomeCommendClass> columList = CrowdHomeCommendCache.getInstance().Load_CrowdHomeCommend_All();
    //数据与样式进行结合，组装
    String tmpStrTuijianList = "";
    if (columList != null && columList.size() > 0) {
        for (CrowdHomeCommendClass obj : columList) {
           
            String cateid = obj.cateid;
            String image = obj.cateimage;
            String catename = obj.catename;
            
          	String kindClass = "";//定义样式
          	
          	String topId ="";//用于即显顶部导航
          	
          
           	
            //现实标签颜色不同
             if(catename.equals("家居")){
	            	kindClass = "index-p";
	            	topId = "t1";
	            }else if(catename.equals("饰品")){
	            	kindClass = "index-r";
	            	topId = "t2";
	            }else if(catename.equals("农副产品")){
	            	kindClass = "index-g";
	            	topId = "t3";
	            }else if(catename.equals("食品")){
	            	kindClass = "index-o";
	            	topId = "t4";
	            }else if(catename.equals("化妆品")){
	            	kindClass = "index-b";
	            	topId = "t5";
	            }



          
            
            tmpStrTuijianList = tmpStrTuijianList + "<section id="+topId+" class=\"topBlank w100 of bcf mgt10\" style=\"padding: 8px 0;\"><a class=\"fl indexKindLable f15 cf "+kindClass+"\">" + catename + "</a><a href=\"mb/jsp/classification.jsp?cateid=" + cateid + "\" class=\"indexKindMore fr f14 tc\">查看更多<img src=\"mb/images/moreArrow.png\" class=\"dib fr\"></a></section>";

            List<CrowdSysProjectClass> childlist = obj.childlist;
            if (columList != null && columList.size() > 0) {
                //for (CrowdSysProjectClass tmp : childlist) {
                for (int i = 0; i < childlist.size(); i++) {
                	CrowdSysProjectClass tmp = childlist.get(i);
                    int state = CacheClass.getIntValue(tmp.state);
                    String stateStr = "";
                    //状态(0下架，1预热，2众筹中，3众筹成功) -> (0下架，1预热，2推荐，3热销，4新品)
                    switch (state) {
                        case 0:
                            stateStr = "下架";
                            break;
                        case 1:
                            stateStr = "预热";
                            break;
                        case 2:
                            stateStr = "推荐";
                            break;
                        case 3:
                            stateStr = "热销";
                        case 4:
                            stateStr = "新品";
                            break;
                    }
                    String projectidStr = tmp.projectid;
                    String supportnumStr = tmp.supportnum;
                    String projectimageStr = tmp.projectimage;
                    if (!CacheClass.isEmpty(projectimageStr))
                        projectimageStr = projectimageStr.split(";")[0];
                    String projectnameStr = tmp.projectname;
                    String companynameStr = tmp.companyname;
                    String packagepriceStr = "￥" + tmp.packageprice;
                    String supportnum =tmp.supportnum;
                    
                    
                    int stocknum=0; 
				    if((CacheClass.getIntValue(tmp.limitenum)-CacheClass.getIntValue(tmp.supportnum))>0)
				          stocknum=CacheClass.getIntValue(tmp.limitenum)-CacheClass.getIntValue(tmp.supportnum);
				    String nowrmbStr = stocknum+"";
                    //String nowrmbStr = "￥" + tmp.nowrmb;
                    
                    
                    String dayStr = tmp.days + "天";
                    
                   
                    
                    
                    	//展示不同的列表布局--二分之一布局          	
			          	String outer = "<section class=\"w100 bcf of\"><div class=\"proSectionLittle w100 bcf clearfix of jz\">";
		            	String outerEnd = "</div></section>";
			         
			           	String proSectionChange = "";
			           	String floatChange ="fr";
			           	
			           	
                     if(childlist.size() % 2 == 0){
                         floatChange="lh15 mgb10";
	                     int numCount = i % 2;
	                    switch(numCount)
							{
							case 0:
							  proSectionChange = "proSection_odd fl";
							  break;
							case 1:
							  proSectionChange = "proSection_even fr";
							  break;
							default:
							  proSectionChange = "proSection";
							}
                     }
                     
                     String vipStr = "<span class=\"" + floatChange + " dib c9 f13\">送VIP"+tmp.viplevel+"级："+dayStr+"</span>";
                     
                     if(tmp.viplevel.equals("0")){
                     	vipStr = "";
                     }
                     
                     
                    String temporarilyStores="<section class=\"" + proSectionChange + " w100 bcf \" onclick=\"window.location.href='mb/jsp/productDetail.jsp?projectid=" + projectidStr + "'\">" +
						                            "<a class=\"proImg db w100 of pr\"><img src=\"" + getImageBasePath(projectimageStr) + "\" class=\"db w100 h100\">"+
						                            	"<span class=\"pa saleNum dib cf f13\">已售"+supportnum+"</span>" +
						                            "</a>" +
						                            "<a class=\"proName db of mgt10 f16\">" + projectnameStr + "</a>" +
						                            "<a class=\"proDetail clearfix of db lh2\"><div class=\"fl f15 orange\">" + packagepriceStr + "</div>"+vipStr+"</a>" +
				                            "</section>";
                    
 					
 					
		                    
		                   
            		//定义不同样式--二分之一布局
            		
                    if(childlist.size() % 2 == 0){
                           
           	                if(i%2==0){
	           	                outer = "<section class=\"w100 bcf of\"><div class=\"proSectionLittle w100 bcf clearfix of jz\">";
	           	                outerEnd ="";
          	                    tmpStrTuijianList = tmpStrTuijianList +outer+
                    						temporarilyStores;
           	                   
           	                  
           	                }else{
           	                 outer = "";
           	                 outerEnd ="</div></section>";
           	                     tmpStrTuijianList = tmpStrTuijianList +
                    						temporarilyStores+
				                            outerEnd;
           	                }
                    }else{
	                    	
	           				  tmpStrTuijianList = tmpStrTuijianList +
                    						temporarilyStores;
                    }
                    
                   

                }
              
            }

		
        }

    }
    //System.out.println(tmpStrTuijianList);
    //数据填充
    //strb = Tools.replaceAll(strb, "[首页推荐列表]", tmpStr);

    /***************** 输出网页到客户端或写入到某html网页作为静态化     *****************/


//    if (v.equals("show")) {    //预览首页,即直接输出网页到客户端
//        out.println(strb);
//    } else {  //生成首页  静态化
//        String modstr = strb.toString();
//        String strFileName = request.getRealPath("/mb/index.html"); //准备保存的静态网页路径及文件名
//        //System.out.println(strFileName);
//        try {
//            FileOutputStream afile = new FileOutputStream(strFileName);
//            afile.write(modstr.getBytes("UTF-8"));
//            afile.close();
//
//            modstr = null;
//        } catch (IOException e) {
//            out.println(e.getMessage());
//        }
//    }

   // strb = null;

%>

<html lang="en">
<head>
    <meta charset="UTF-8">

    <title></title>
    <script type="text/javascript">
    	$(window).on("load", function() {
				$("#footer").load("mb/footer.jsp", function() {
				  footerTab(1);
				});
	    })
   
    
        var timer = null;

        $(document).ready(function () {
//            图片滑动
            $dragBln = false;
            $(".main_image").touchSlider({
                flexible: true,
                speed: 200,
                btn_prev: $("#btn_prev"),
                btn_next: $("#btn_next"),
                paging: $(".flicking_con a"),
                counter: function (e) {
                    $(".flicking_con a").removeClass("on").eq(e.current - 1).addClass("on");
                }
            });

            $(".main_image").bind("mousedown", function () {
                $dragBln = false;
            });

            $(".main_image").bind("dragstart", function () {
                $dragBln = true;
            });

            $(".main_image a").click(function () {
                if ($dragBln) {
                    return false;
                }
            });
           $(".main_visual").hover(function () {
                clearInterval(timer);
            }, function () {
                timer = setInterval(function () {
                    $("#btn_next").click();
                }, 5000);
            });

            $(".main_image").bind("touchstart", function () {
                clearInterval(timer);
            }).bind("touchend", function () {
                timer = setInterval(function () {
                    $("#btn_next").click();
                }, 5000);
            }); 
            
            

            //            进度条
            /* $(".bar_span").each(function () {
                var ress = $(this).attr('width');
                //var len = ress + "%";
                 var len = ress;
                $(this).animate({
                    width: len
                });

            }) */
            
            
            
            //即显标题
            
            	$(window).scroll(function(){
						var h=$(this).scrollTop();//获得滚动条距top的高度
						var htmlStr = "";
						var Nofixer =  $(".topBlank").removeClass("fixer");
						
						  if(h < 342 ){
						       	Nofixer;
						    }
						  if(h > $("#t1").offset().top ){
						   		Nofixer;
						  		$("#t1").addClass("fixer");
						    }
						  if(h > $("#t2").offset().top){
						       Nofixer;
						  		$("#t2").addClass("fixer");
						    }
						  if(h > $("#t3").offset().top){
						       Nofixer;
						  		$("#t3").addClass("fixer");
						    } 
						   if(h > $("#t4").offset().top){
						       Nofixer;
						  		$("#t4").addClass("fixer");
						    }
						    if(h > $("#t5").offset().top){
						        Nofixer;
						  		$("#t5").addClass("fixer");
						    }
						
			});

        });
    </script>

</head>
<body ontouchstart="">
<div class="container jz">
    <div class="main_visual">
        <div class="flicking_con w100">
            <div class="dib jz">
                <%
                    out.print(tmpStrAdvround);
                %>
            </div>
        </div>
        <div class="main_image">
            <ul>
                <%
                    out.print(tmpStrAdvImage);
                %>
            </ul>
        </div>
    </div>
    <!--main_visual-->
    <nav class="w100" id="main_visual" style="padding-top:5px;padding-bottom:5px;">
        <%
           // out.print(tmpStrFastMenu); 
            System.out.println(tmpStrFastMenu);
        %>
    </nav>

    <%
        out.print(tmpStrTuijianList);
    %>
</div>

  	<!--footer-->
<footer id="footer" class="footerTab w100 of pf">
 
</footer>

<script>

   
    window.addEventListener('pageshow', function (event) {
        // 获取localStore中的变量
        var needrefresh = localStorage.getItem("needrefreshindex"); //存储变量名为key，值为value的变量
        if (needrefresh != '' && needrefresh != null && needrefresh == 'true') {
            localStorage.removeItem("needrefreshindex");
            window.location.reload();
        }
    });

$(document).ready(function(){
	$("#main_visual").html('');
	$("#main_visual").html('<%=tmpStrFastMenu%>');

});


</script>
<!-- <section id="fixer" class="fixer pf of w100 clearfix bcf"></section> -->
</body>
</html>